<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据统计</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="bg-warp">
        <d:hasUrlAuth authCode="RZSC_OPERATION_ORG_SEARCH">
        <form id="searchForm" action="${basePath}/rzsc_count/export_order_count_data.do">
        <div class="screen-module">
            <ul class="screen-search">
                <li>
                    <label>事业部：</label>
                        <select class="dggui-select" id="signOrgId" name="signOrgId">
                        </select>
                </li>
                <li>
                    <button class="dggui-btn"  onclick="refreshData();return false;">搜索</button>
                    <button class="dggui-btn dggui-btn-primary"  onclick="exportOrderCount();return false;">导出</button>
                </li>
            </ul>
        </div>
        </form>
        </d:hasUrlAuth>
        <div class="dggui-panel">
            <h3>生产系统数据统计</h3>
            <table class="dggui-table cell-border">
                <thead>
                <th>事业部</th>
                <th>待分配</th>
                <th>待接收</th>
                <th>办理中</th>
                <th>已暂缓</th>
                <th>退单待审核</th>
                <th>废单待审核</th>
                <th>退单驳回</th>
                <th>废单驳回</th>
                <th>已退单</th>
                <th>已废单</th>
                <th>生产完结</th>
                <th>合计</th>
                </thead>
                <tbody id="scOrderCount">
                </tbody>
                <tfoot>
                </tfoot>
            </table>
        </div>
        <div class="dggui-panel">
            <h3>统计图</h3>
            <div id="container" style="width: 100%;height: 500px;padding: 15px">

            </div>
        </div>
    </div>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script type="text/javascript">
    var chart;
    dggui.use(['chart','select2'], function(){
        chart = dggui.chart;
        var select2 = dggui.select2;
        //初始化所属生产事业部
        syb("#signOrgId");
        loadScOrderAccount('#scOrderCount');

        select2.render({
            placeholder: "请选择",
            elem: $('#signOrgId'),
            allowClear: true,
            width: "190px"
        });

    });

    function refreshData() {
        var signOrgId = $("#signOrgId").val();
        loadScOrderAccount('#scOrderCount', signOrgId);
    }

    function checkHasSybAuth(obj) {
        var count = obj.length;
        if (checkIsEmpty(count) || count === 0) {
            return false;
        }
        return true;
    }

    /**
     * 加载统计数据信息
     */
    function loadScOrderAccount(obj, signOrgId) {
        var params = {};
        var checkResult = checkHasSybAuth($('#signOrgId option'));
        if (!checkResult) {
            params.isAll = "0";
        }else {
            params.isAll = "1";
        }
        if (!checkIsEmpty(signOrgId)) {
            params.signOrgId = signOrgId;
        }
        $.post(sysInfo.basePath + "/rzsc_count/sc_order_count_data.do", params, function (result) {
            if (result.code == 0) {
                $(obj).empty();
                var datas = result.data.orderCount;
                if (!checkIsEmpty(datas) && datas.length > 0) {
                    $.each(datas, function (i, item) {
                        $(obj).append("<tr>\n" +
                            "<td>" + item.productOrgName + "</td>\n" +
                            "<td>" + item.waitAllotCount + "</td>\n" +
                            "<td>" + item.waitReceiveCount + "</td>\n" +
                            "<td>" + item.inprocessCount + "</td>\n" +
                            "<td>" + item.suspendCount + "</td>\n" +
                            "<td>" + item.tddshCount + "</td>\n" +
                            "<td>" + item.fddshCount + "</td>\n" +
                            "<td>" + item.tdbhCount + "</td>\n" +
                            "<td>" + item.fdbhCount + "</td>\n" +
                            "<td>" + item.ytdCount + "</td>\n" +
                            "<td>" + item.yfdCount + "</td>\n" +
                            "<td>" + item.scwjCount + "</td>\n" +
                            "<td>" + item.total + "</td>\n" +
                            "</tr>");
                    });
                } else {
                    $(obj).append("<tr>\n" +
                        "<td colspan='13'><center>没有数据</center></td>\n" +
                        "</tr>");
                }
                var orderTotal = result.data.orderTotal;
                if (checkIsEmpty(signOrgId) && !checkIsEmpty(orderTotal)) {
                    $(obj).append("<tr>\n" +
                        "<td style='color: red'>总计</td>\n" +
                        "<td style='color: red'>" + orderTotal.waitAllotTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.waitReceiveTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.inprocessTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.suspendTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.tddshTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.fddshTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.tdbhTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.fdbhTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.ytdTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.yfdTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.scwjTotal + "</td>\n" +
                        "<td style='color: red'>" + orderTotal.allTotal + "</td>\n" +
                        "</tr>");
                }
                //柱形图初始化
                chushihua(result);
            } else {
                dggui.dialog.errors(result.msg);
                return false;
            }
        });
    }


    //柱形图初始化
    function chushihua(result) {
        var orderCountList = result.data.orderCount;
        var nameData = [];//事业部名字
        var waitAllotCount = [];//待分配
        var waitReceiveCount = [];//待接收
        var inprocessCount = [];//办理中
        var suspendCount = [];//暂停
        var tddshCount = [];//退单待审核
        var fddshCount = [];//废单待审核
        var tdbhCount = [];//退单驳回
        var fdbhCount = [];//废单驳回
        var ytdCount = [];//已退单
        var yfdCount = [];//已废单
        var scwjCount = [];//生产完结
        for (var i = 0;i < orderCountList.length;i ++){
            nameData.push(orderCountList[i].productOrgName);
            waitAllotCount.push(orderCountList[i].waitAllotCount);
            waitReceiveCount.push(orderCountList[i].waitReceiveCount);
            inprocessCount.push(orderCountList[i].inprocessCount);
            suspendCount.push(orderCountList[i].suspendCount);
            tddshCount.push(orderCountList[i].tddshCount);
            fddshCount.push(orderCountList[i].fddshCount);
            tdbhCount.push(orderCountList[i].tdbhCount);
            fdbhCount.push(orderCountList[i].fdbhCount);
            ytdCount.push(orderCountList[i].ytdCount);
            yfdCount.push(orderCountList[i].yfdCount);
            scwjCount.push(orderCountList[i].scwjCount);
        }
        chart.render({
            elem:'container',   //挂载的元素，必须为id
            option : {   //图表的参数
                tooltip : {
                    trigger: 'axis',
                    axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                        type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                legend: {
                    data:['待分配', '待接收','办理中','已暂缓','退单待审核','废单待审核','退单驳回','废单驳回','已退单','已废单','生产完结']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '20%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value'
                },
                yAxis: {
                    type: 'category',
                    data: nameData
                },
                series: [
                    {
                        name: '待分配',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:waitAllotCount
                    },
                    {
                        name: '待接收',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:waitReceiveCount
                    },
                    {
                        name: '办理中',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:inprocessCount
                    },
                    {
                        name: '已暂缓',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:suspendCount
                    },
                    {
                        name: '退单待审核',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:tddshCount
                    },
                    {
                        name: '废单待审核',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:fddshCount
                    },
                    {
                        name: '退单驳回',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:tdbhCount
                    },
                    {
                        name: '废单驳回',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:fdbhCount
                    },
                    {
                        name: '已退单',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:ytdCount
                    },
                    {
                        name: '已废单',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:yfdCount
                    },
                    {
                        name: '生产完结',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                position: 'insideRight'
                            }
                        },
                        data:scwjCount
                    },
                    ]
            }
        })
    }

    /**
     * 导出
     */
    function exportOrderCount() {
        $("#searchForm").submit();
    }
</script>
</body>
</html>